package com.whnk.web.controller.pm;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.WdInfo;
import com.whnk.pm.service.IWdInfoService;

/**
 * 工作日历 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-11
 */
@Controller
@RequestMapping("/pm/wdInfo")
public class WdInfoController extends BaseController
{
    private String prefix = "pm/wdInfo";
	
	@Autowired
	private IWdInfoService wdInfoService;
	
	@RequiresPermissions("pm:wdInfo:view")
	@GetMapping()
	public String wdInfo()
	{
	    return prefix + "/wdInfo";
	}
	
	/**
	 * 查询工作日历列表
	 */
	@RequiresPermissions("pm:wdInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WdInfo wdInfo)
	{
		startPage();
        List<WdInfo> list = wdInfoService.selectWdInfoList(wdInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增工作日历
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存工作日历
	 */
	@RequiresPermissions("pm:wdInfo:add")
	@Log(title = "工作日历", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WdInfo wdInfo)
	{		
		return toAjax(wdInfoService.insertWdInfo(wdInfo));
	}

	/**
	 * 修改工作日历
	 */
	@GetMapping("/edit/{wdId}")
	public String edit(@PathVariable("wdId") Integer wdId, ModelMap mmap)
	{
		WdInfo wdInfo = wdInfoService.selectWdInfoById(wdId);
		mmap.put("wdInfo", wdInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存工作日历
	 */
	@RequiresPermissions("pm:wdInfo:edit")
	@Log(title = "工作日历", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WdInfo wdInfo)
	{		
		return toAjax(wdInfoService.updateWdInfo(wdInfo));
	}
	
	/**
	 * 删除工作日历
	 */
	@RequiresPermissions("pm:wdInfo:remove")
	@Log(title = "工作日历", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wdInfoService.deleteWdInfoByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param wdId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:wdInfo:detail")
    @GetMapping("/detail/{wdId}")
    public String detail(@PathVariable("wdId") Integer wdId, ModelMap mmap)
    {
		WdInfo wdInfo = wdInfoService.selectWdInfoById(wdId);
		mmap.put("wdInfo", wdInfo);
        return prefix + "/detail";
    }
	
	
	/**
	 * 根据输入的年份，生成日历数据
	 * 
	 * @param wdYear
	 * @return
	 */
	@PostMapping("/createWorkDt")
    @ResponseBody
    public AjaxResult createWorkDt(Integer wdYear) {
		return toAjax(wdInfoService.createWorkDt(wdYear));
    }
}
